﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using DataAccessLayer;

namespace BusinessLayer
{
    public class Add_Users_Profile
    {
        public string userid { get; set; }
        public string fname { get; set; }
        public string lname { get; set; }
        public string identity { get; set; }
        public string address { get; set; }
        public string contact { get; set; }
        public string username { get; set; }

        public Add_Users_Profile()
        {
            userid = "";
            fname = "";
            lname = "";
            identity = "";
            address = "";
            contact = "";
            username = "";
        }

        public Add_Users_Profile(string uid, string fnam, string lnam, string id, string addr, string cont, string usern)
        {
            userid = uid;
            fname = fnam;
            lname = lnam;
            identity = id;
            address = addr;
            contact = cont;
            username = usern;
        }
        //Add Profile
        public void add_users_pro()
        {
            DataAccessLayer.csDAL objdal = new DataAccessLayer.csDAL();
            List<csparameterListType> par = new List<csparameterListType>();

            par.Add(new csparameterListType("@UserId", SqlDbType.NVarChar, userid));
            par.Add(new csparameterListType("@Username", SqlDbType.NVarChar, username));
            par.Add(new csparameterListType("@IdNumber", SqlDbType.VarChar, identity));
            par.Add(new csparameterListType("@FirstName", SqlDbType.VarChar, fname));
            par.Add(new csparameterListType("@LastName", SqlDbType.VarChar, lname));
            par.Add(new csparameterListType("@ContactNo", SqlDbType.VarChar, contact));
            par.Add(new csparameterListType("@Physical_Address", SqlDbType.VarChar, address));

            objdal.executespreturnnd("Add_User_Profile", par);
        }
        //Get User Profile
        public List<Add_Users_Profile> getuser_info()
        {
            List<csparameterListType> par = new List<csparameterListType>();
            List<Add_Users_Profile> objlist = new List<Add_Users_Profile>();
            DataAccessLayer.csDAL objdal = new DataAccessLayer.csDAL();
            IDataReader datareader = null;

            datareader = objdal.executespreturndr("Get_User_Profile");
            while (datareader.Read())
            {
                Add_Users_Profile objP = new Add_Users_Profile();
                populate_reader(datareader, objP);
                objlist.Add(objP);
            }
            return objlist;
        }

        private void populate_reader(IDataReader datareader, Add_Users_Profile objP)
        {
            objP.userid = datareader.GetString(0);
            objP.username = datareader.GetString(1);
            objP.identity = datareader.GetString(2);
            objP.fname = datareader.GetString(3);
            objP.lname = datareader.GetString(4);
            objP.contact = datareader.GetString(5);
            objP.address = datareader.GetString(6);
        }

        //Update User - NOT WORKING YET
        public void update_user_profile()
        {
            DataAccessLayer.csDAL objdal = new DataAccessLayer.csDAL();
            List<csparameterListType> par = new List<csparameterListType>();

            par.Add(new csparameterListType("@UserId", SqlDbType.NVarChar, userid));
            par.Add(new csparameterListType("@IdNumber", SqlDbType.VarChar, identity));
            par.Add(new csparameterListType("@FirstName", SqlDbType.VarChar, fname));
            par.Add(new csparameterListType("@LastName", SqlDbType.VarChar, lname));
            par.Add(new csparameterListType("@ContactNo", SqlDbType.VarChar, contact));
            par.Add(new csparameterListType("@Physical_Address", SqlDbType.VarChar, address));

            objdal.executespreturnnd("Update_User_Profile", par);
        }
    }
}